<form method="post" action="<?php echo mns_page_url(PRODUCT_SLUG.'/cap-nhat'); ?>" data-callback='1'>
    <div class="row">
        <h1 class="col-md-6">Sản phẩm <small>Cập nhật thông tin sản phẩm</small></h1>
        <h1 class="col-md-6">
            <a class="btn btn-default pull-right mgl5" href="<?php echo mns_page_url(PRODUCT_SLUG); ?>">
                <i class='glyphicon glyphicon-share-alt'></i>
                Trở về
            </a>
            <a class="btn btn-primary pull-right mgl5" href="<?php echo mns_page_url(PRODUCT_SLUG.'/them'); ?>">
                <i class='glyphicon glyphicon-plus-sign'></i>
                Thêm mới
            </a>
            <a id="preview-product" target="_blank" class="btn btn-primary pull-right mgl5" href="<?php echo product_url($product->getSlug()); ?>">
                <i class="glyphicon glyphicon-search"></i>
                Xem
            </a>
            <button type="button" class="btn btn-success btn-submit-update pull-right">
                <i class='glyphicon glyphicon-ok-sign'></i>
                Cập nhật
            </button>
        </h1>
        <div class="col-md-12">
            <ol class="breadcrumb">
                <li><a href="<?php echo mns_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
                <li><a href="<?php echo mns_product_url(); ?>"><i class="fa fa-table"></i> Sản phẩm</a></li>
                <li class="active"><i class="fa fa-table"></i> <?php echo $product->getTitle(); ?></li>
            </ol>
        </div>
        <div class="clearfix"></div>
    </div>

    <div class='row'>
        <div class="form-group col-md-9 col-xs-12">
            <label for="input-product-title">Tên</label>
            <input type="text" class="form-control auto-slug" id="input-product-title" name="product[title]" follow-ctr="#input-product-slug" value="<?php echo $product->getTitle(); ?>" />
            <input type="hidden" name="product[id]" value="<?php echo $this->encrypt->encode($product->getId()); ?>" />
        </div>

        <div class="form-group col-md-9 col-xs-12">
            <label for="input-product-slug">Đường dẫn</label>
            <input type="text" class="form-control" id="input-product-slug" name="product[slug]" value="<?php echo $product->getSlug(); ?>"/>
        </div>
        <div class="clearfix"></div>

        <div class="form-group col-md-3 col-xs-12">
            <label for="input-product-cate">Danh mục</label>
            <select id="input-product-cate" class="form-control" name="product[product_cate]">
                <?php foreach($aProductCate as $cate) {?>
                <option value="<?php echo $cate->getId(); ?>" <?php echo $cate->getId()==$product->getShopCateId()?'selected="selected"':''; ?>>
                    <?php echo $cate->getTitle(); ?>
                </option>
                <?php } ?>
            </select>
        </div>

        <div class="col-md-9 col-xs-12">
            <div class="checkbox inline-table clearMgr">
                <input class="lb-toggle" type="checkbox" id="input-product-sale-flg" name="product[sale_flg]" value="1" <?php echo $product->getSaleFlg()==ON?'checked="checked"':''; ?> /> Giảm giá
                <label for="input-product-sale-flg"></label>
            </div>
            <div class="checkbox inline-table clearMgr">
                <input class="lb-toggle" type="checkbox" id="input-product-active-flg" name="product[active_flg]" value="1" <?php echo $product->getActiveFlg()==ON?'checked="checked"':''; ?> />Hiển thị
                <label for="input-product-active-flg"></label>
            </div>
            <div class="checkbox inline-table clearMgr">
                <input class="lb-toggle" type="checkbox" id="input-product-delete-flg" name="product[delete_flg]" value="1" <?php echo $product->deleted_at!=NULL?'checked="checked"':''; ?> /> Xoá
                <label for="input-product-delete-flg"></label>
            </div>
            <button class="btn btn-primary mgl10 mgt15" type="button" onclick="addTempRowProduct();" >
                <i class="glyphicon glyphicon glyphicon-plus"></i>
                Thêm chi tiết
            </button>
            <input type="hidden" name="product[update_case]" value="<?php echo UPDATE_FULL; ?>" />
        </div>

        <div class="col-md-12">
            <div class="table-responsive">
                <table id="product-in-set-list" class="table table-bordered table-hover tablesorter item-list">
                    <thead>
                        <tr>
                            <th class="header"># <i class="fa fa-sort"></i></th>
                            <th class="header">&nbsp;</th>
                            <th class="header">Sản phẩm</th>
                            <th class="header">Mô tả</th>
                            <th class="header">&nbsp;</th>
                        </tr>
                        <tr class="tr-temp hidden bg-warning">
                            <th class="product-index">&nbsp;</th>
                            <td class="col-md-1 col-xs-4">
                                <div class="media has-change-img-control">
                                    <a class="product-detail-img thumbnail" rel="group" href="#">
                                        <img class="media-object" />
                                        <input type="hidden" data-name="product_detail[index][image]" class="input-product-img" value="" />
                                    </a>
                                    <div class="img-control-product">
                                        <a class="btn btn-success btn-sm" href="#">
                                            <i class='glyphicon glyphicon-edit'></i>
                                            Hình ảnh
                                        </a>
                                    </div>
                                </div>
                            </td>
                            <td class="col-md-2 col-xs-5">
                                <label class="normal">
                                    Mã sản phẩm
                                    <input type="text" class="form-control" id="input-product-detail-code"
                                    data-name="product_detail[index][code]" value=""/>
                                </label>
                                <br />
                                <label class="normal">
                                    Giá cũ
                                    <input type="text" class="form-control" id="input-product-detail-price-old"
                                    data-name="product_detail[index][price_old]" value=""/>
                                </label>
                                <br />
                                <label class="normal">
                                    Giá mới
                                    <input type="text" class="form-control" id="input-product-detail-price-new"
                                    data-name="product_detail[index][price_new]" value=""/>
                                </label>
                            </td>
                            <td>
                                <textarea id="input-product-detail-description" data-name="product_detail[index][description]" class="form-control" rows="5"></textarea>
                            </td>
                            <td class="col-md-2 col-xs-4">
                                <label class="normal">
                                    <input type="checkbox" id="input-product-detail-is-avatar" data-name="product_detail[index][is_avatar]" value="1" />
                                    Sản phẩm chính
                                </label>
                                <br />
                                <label class="normal">
                                    <input type="checkbox" id="input-product-detail-publish-flg" data-name="product_detail[index][publish_flg]" value="1" checked="checked" />
                                    Hiển thị
                                </label>
                                <br />
                                <button class="btn btn-sm btn-danger inline-delete-row" type="button">
                                    <i class='glyphicon glyphicon-minus-sign'></i>
                                    Xoá
                                </button>
                            </td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach($aProductInSet as $index=>$pis) { ?>
                        <tr class="">
                            <th><?php echo $index+1; ?></th>
                            <td class="col-md-1 col-xs-4">
                                <div class="media has-change-img-control">
                                    <?php if($pis->getImage()!='') { ?>
                                    <?php $pImageThumb = product_upload($pis->getImage(), $product->shop_image_folder); ?>
                                    <?php $pImage      = product_upload($pis->getImage(), $product->shop_image_folder, false); ?>
                                    <a title="<?php echo $pis->getCode(); ?>" class="product-detail-img thumbnail fancybox" rel="group" href="<?php echo $pImage; ?>">
                                        <img class="media-object" src="<?php echo $pImageThumb; ?>" />
                                        <input type="hidden" name="product_detail[<?php echo $index+1; ?>][image]" class="input-product-img" value="<?php echo PRODUCT_IMAGE_URL.$pis->getImage(); ?>" />
                                    </a>
                                    <?php } else { ?>
                                    <a title="<?php echo $pis->getCode(); ?>" class="product-detail-img thumbnail fancybox" rel="group" href="#">
                                        <img data-src="holder.js/100%x90" class="media-object minW-96" />
                                        <input type="hidden" name="product_detail[<?php echo $index+1; ?>][image]" class="input-product-img" value="" />
                                    </a>
                                    <?php } ?>
                                    <div class="img-control-product">
                                        <a class="btn btn-success btn-sm" href="#">
                                            <i class='glyphicon glyphicon-edit'></i>
                                            Hình ảnh
                                        </a>
                                    </div>
                                </div>
                            </td>
                            <td class="col-md-2 col-xs-5">
                                <label class="normal">
                                    Mã sản phẩm
                                    <input type="text" class="form-control" id="input-product-detail-code"
                                    name="product_detail[<?php echo $index+1; ?>][code]" value="<?php echo $pis->getCode(); ?>"/>
                                </label>
                                <br />
                                <label class="normal">
                                    Giá cũ
                                    <input type="text" class="form-control" class="input-product-detail-price-old"
                                    name="product_detail[<?php echo $index+1; ?>][price_old]" value="<?php echo $pis->getPriceOld(); ?>"/>
                                </label>
                                <br />
                                <label class="normal">
                                    Giá mới
                                    <input type="text" class="form-control" class="input-product-detail-price-new"
                                    name="product_detail[<?php echo $index+1; ?>][price_new]" value="<?php echo $pis->getPriceNew(); ?>"/>
                                </label>
                            </td>
                            <td>
                                <textarea id="input-product-detail-description" name="product_detail[<?php echo $index+1; ?>][description]" class="form-control" rows="5"><?php echo $pis->getDescription(); ?></textarea>
                            </td>
                            <td class="col-md-2 col-xs-4">
                                <label class="normal">
                                    <input type="checkbox" class="input-product-detail-is-avatar" name="product_detail[<?php echo $index+1; ?>][is_avatar]" value="1"
                                    <?php if($pis->getIsAvatar()==1) { ?> checked="checked" <?php } ?> />
                                    Sản phẩm chính
                                </label>
                                <br />
                                <label class="normal">
                                    <input type="checkbox" class="input-product-detail-publish-flg" name="product_detail[<?php echo $index+1; ?>][publish_flg]" value="1"
                                    <?php if($pis->getDeletedAt()==NULL) { ?> checked="checked" <?php } ?> />
                                    Hiển thị
                                </label>
                                <input type="hidden" name="product_detail[<?php echo $index+1; ?>][id]" value="<?php echo $this->encrypt->encode($pis->getId()); ?>" />
                                <br />
                                <button class="btn btn-sm btn-danger inline-delete-row" type="button">
                                    <i class='glyphicon glyphicon-minus-sign'></i>
                                    Xoá
                                </button>
                            </td>
                        </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>

    <div class="row">
        <div class="col-md-6 col-xs-12 col-md-offset-6">
            <a class="btn btn-default pull-right mgl5" href="<?php echo mns_page_url(PRODUCT_SLUG); ?>">
                <i class='glyphicon glyphicon-share-alt'></i>
                Trở về
            </a>
            <a class="btn btn-primary pull-right mgl5" href="<?php echo mns_page_url(PRODUCT_SLUG.'/them'); ?>">
                <i class='glyphicon glyphicon-plus-sign'></i>
                Thêm mới
            </a>
            <a id="preview-product" target="_blank" class="btn btn-primary pull-right mgl5" href="<?php echo product_url($product->getSlug()); ?>">
                <i class="glyphicon glyphicon-search"></i>
                Xem
            </a>
            <button type="button" class="btn btn-success btn-submit-update pull-right">
                <i class='glyphicon glyphicon-ok-sign'></i>
                Cập nhật
            </button>
        </div>
    </div>
</form>
<?php $this->load->view('backend/shop/product/image-modal.html.php', array('lastProduct'=>$product)); ?>